package arithmetic;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: javaLearn
 * @description: 类脑智能查询小于等于6的环路
 * @author: renhai
 * @Date ：2022/4/19 15:48
 **/
public class FindRings {
    static List<String> LinkedList = new ArrayList<>();


    static boolean isLink(int num1, int num2) {

        return (LinkedList.contains(num1 + " " + num2));
    }

    public static void readTxt(String filePath) {
        try {
            File file = new File(filePath);
            if (file.isFile() && file.exists()) {
                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
                BufferedReader br = new BufferedReader(isr);
                String lineTxt = null;
                while ((lineTxt = br.readLine()) != null) {
                    LinkedList.add(lineTxt.split("\t")[0] + " " + lineTxt.split("\t")[1]);
                }
                br.close();
            } else {
                System.out.println("文件不存在!");
            }
        } catch (Exception e) {
            System.out.println("文件读取错误!");
        }
    }

    public static void main(String[] args) {
        readTxt("C:\\Users\\86158\\Desktop\\类脑智能本科课题研究\\realyLink.txt");
        //三元环
        for (int i = 1; i <= 48; i++) {
            for (int j = i + 1; j <= 48; j++) {
                if (isLink(i, j)) {
                    for (int k = j + 1; k <= 48; k++) {
                        if (isLink(j, k)) {
                            if (isLink(i, k)) {
                                System.out.println("三元环路->" + i + "->" + j + "->" + k + "->" + i);
                            }
                        }
                    }
                }
            }
        }
        //四元环
//        for (int i = 1; i <= 48; i++) {
//            for (int j = i + 1; j <= 48; j++) {
//                if (isLink(i, j)) {
//                    for (int k = j + 1; k <= 48; k++) {
//                        if (isLink(j, k)) {
//                            for (int m = k + 1; m <= 48; m++) {
//                                if (isLink(k, m)) {
//                                    if (isLink(i, m)) {
//                                        System.out.println("四元环路->" + i + "->" + j + "->" + k + "->" + m + "->" + i);
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }

    }
}
